<template>
	<view class="login">
		<image src="../../static/images/money.png" mode=""></image>
		<view class="btn" @click="login">微信登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			login() {
				let _this = this;
				let code;
				uni.login({
					provider: 'weixin',
					success: res => {
						code = res.code; //获取登录需要的code
						let data = {}; //授权拿到用户信息
						data.code = code;
						_this.$cloudApi.call({
							name: 'login',
							data,
							success: res => {
								console.log(res);
								uni.setStorageSync('userInfo', res.userInfo); //拿到后台返回的用户信息
								uni.showToast({
									title: '登录成功',
									icon: 'success',
								});
								uni.reLaunch({
									url: '/pages/index/index'
								})
							}
						});
					}
				});
			}
		}
	}
</script>

<style scoped lang="less">
	.login {
		padding: 10rpx;
		position: absolute;
		width: 100%;
		height: 100%;
		box-sizing: border-box;

		image {
			width: 250rpx;
			height: 250rpx;
			position: absolute;
			top: 35%;
			right: 35%;
		}

		.btn {
			position: absolute;
			top: 60%;
			right: 38%;
			padding: 20rpx;
			background: #007AFF;
			color: #fff;
			border-radius: 20rpx;
		}
	}
</style>